package club.justwill.single.persistence.jpo;

import club.justwill.single.persistence.support.ProjectBackBase;
import club.justwill.single.persistence.support.ProjectBackPK;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by xiangnan on 15-12-30.
 */
@Entity
@Table(name = "project_back")
@IdClass(ProjectBackPK.class)
public class ProjectBack extends ProjectBackBase {

    @Id
    @Column(name = "main_project_id")
    private long mainProjectId;

    @Id
    @Column(name = "slave_project_id")
    private long slaveProjectId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "main_project_id", referencedColumnName = "project_id", insertable = false, updatable = false)
    private Projects mainProject;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "slave_project_id", referencedColumnName = "project_id", insertable = false, updatable = false)
    private Projects slaveProject;

    public Projects getMainProject() {
        return mainProject;
    }

    public void setMainProject(Projects mainProject) {
        this.mainProject = mainProject;
    }

    public Projects getSlaveProject() {
        return slaveProject;
    }

    public void setSlaveProject(Projects slaveProject) {
        this.slaveProject = slaveProject;
    }

    public long getMainProjectId() {
        return mainProjectId;
    }

    public void setMainProjectId(Long mainProjectId) {
        if(mainProjectId == null) {
            this.mainProjectId = 0L;
        } else {
            this.mainProjectId = mainProjectId;
        }
    }

    public long getSlaveProjectId() {
        return slaveProjectId;
    }

    public void setSlaveProjectId(Long slaveProjectId) {
        if(slaveProjectId == null) {
            this.slaveProjectId = 0L;
        } else {
            this.slaveProjectId = slaveProjectId;
        }
    }

}
